<{include file="Public/top.html" }>
</head>
	<body>
		<div id="warpper">
            <div class="content">
                <div class="location">会员活动</div>
                <{include file="./nav.html" }>
                <div class="topic">新增活动</div>
                <form action="<{U('Events/edit')}>" method="post" class="ui-form">
                <div class="form-box border0 border-box">
                    <div class="ui-form-item ">
                        <label class="ui-label">标题</label>
                        <input type="text" class="ui-text" name="title" value="<{$data['title']}>" required/>
                    </div>

                    <div class="ui-form-item2 inline-block uploader">
                        <label class="ui-label ">封面图片</label>
                            <span class="picture_box picture_270">
                                <div class="a-imgBox" id="imgBox" <{if $data['imgList']}>style="display:block"<{else}>style="display:none;"<{/if}> >
                                    <a href="javascript:;" class="a-close" onclick="deleteListPic()"></a>
                                    <img src="<{$data['imgList']}>" width="270" height="169" />
                                </div>
                                <div>
                                    <a href="javascript:;" class="a-upload">
                                        <input type="file" name="file" >
                                    </a>
                                    <i class="uptxt">上传图片</i>
                                    <i>598*332</i>
                                </div>
                            </span>
                        <input type="hidden" value="<{$data['imgList']}>" id="imgList" name="imgList" class="ui-button"/>
                    </div>

                    <div class="ui-form-item">
                        <label class="ui-label ">活动时间</label>
                        <input type="text" class="ui-text" id="showEventsDate" value="<{$data['showListTime']}>" name="showListTime" placeholder="例如：2016-04-15  周五" required/>
                        <i>仅用于前端列表显示</i>
                    </div>
                    <div class="ui-form-item" style="vertical-align:top;">
                        <label class="ui-label">活动地址</label>
                        <input class="ui-text " name="location" value="<{$data['location']}>" type="text"  placeholder="不超过20个字" maxlength="20"/>
                    </div>
                    <div class="ui-form-item" style="vertical-align:top;">
                        <label class="ui-label">备选地址</label>
                        <span>
                            <textarea class="ui-textarea " name="addressPool" ><{$data['addressPool']}></textarea>
                            <div style="white-space:nowrap">活动有多个地址可供选择时设置，一行一个地址</div>
                        </span>
                    </div>


                    <div class="ui-form-item" >
                        <label class="ui-label">其它备选</label>
                        <span style="width: 500px">
                            <div >名称：<input class="ui-text " name="otherTitle" value="<{$data['otherTitle']}>"/></div>
                            <div>选项：<textarea class="ui-textarea " name="otherPool"  ><{$data['otherPool']}></textarea></div>
                            <div style="white-space:nowrap">一行一个选项</div>
                        </span>
                    </div>



                    <div class="ui-form-item" >
                        <label class="ui-label">更多参数 <a href="javascript:void(0)" onclick="addExt()">+</a></label>
                        <span style="width: 400px;">
                            <ul id="other">
                                <{foreach from=$ext item=item}>
                                <li>
                                    <span >字段名称<a href="javascript:void(0)" onclick="delExt(this)">(删除)</a>：<input class="ui-text " name="field_title[]" value="<{$item['title']}>" style="display: inline-block;width: 6rem"/></span>
                                    <span style="display: inline-block">补充说明：<input class="ui-text "  name="field_tip[]"  value="<{$item['tip']}>"></input></span>
                                </li>
                                <{/foreach}>

                            </ul>
                        </span>
                    </div>



                    <{if $channels}>
                        <div class="ui-form-item">
                            <label class="ui-label">栏目</label>
                            <{html_checkboxes name="channel" options=$channels checked=$selectedChannels separator="&nbsp;"}>
                        </div>
                    <{/if}>
                    <div class="ui-form-item ">
                        <label class="ui-label">标签</label>
                        <select id="eventsType" name="contentType" class="ui-select">
                            <{foreach from = $eventsType key=key item=item}>
                            <option value="<{$key}>" <{if $key eq $data['contentType']}>selected<{/if}>><{$item}></option>
                            <{/foreach}>
                        </select>
                        <!--<input type="button" id="eventsTypeManage" value="标签管理" class="ui-button"/>-->
                    </div>

                    <{if $businessSwitch}>
                        <div class="ui-form-item">
                            <label class="ui-label">商务经理</label>
                            <input type="radio" value="0" name="business" checked/>不选
                            <{html_radios name="business" options=$sysUser selected=$selectedSysUser separator="&nbsp;"}>
                        </div>
                    <{/if}>
                    <{if $askUserLevel}>
                        <div class="ui-form-item ">
                            <label class="ui-label">会员等级</label>
                            <select name="userLevel" class="ui-select">
                                <option value="0"></option>
                                <{foreach from = $userLevel key=key item=item}>
                                <option value="<{$key}>" <{if $key eq $data['userLevel']}>selected<{/if}>><{$item}></option>
                                <{/foreach}>
                            </select>
                        </div>
                    <{/if}>
                    <div class="ui-form-item">
                        <label class="ui-label">关联门店</label>
                        <select name="relatedStore" class="ui-select">
                            <option value="0">无关联门店</option>
                            <{html_options  options=$storeKv selected=$data['relatedStore'] }>
                        </select>
                    </div>


                    <div class="ui-form-item">
                        <label class="ui-label">宝贝信息要求开关</label>
                        <span style="width: 50%;font-size: smaller">
                            <div class="ui-form-item ">
                                <label class="ui-label">昵称要求</label>
                                <input type="radio"  <{if $data['needNickname'] neq 1}>checked<{/if}> value="0" name="needNickname" id="noneedn"><label for="noneedn">不启用</label>&nbsp;&nbsp;
                                <input type="radio"  <{if $data['needNickname'] eq 1}>checked<{/if}> value="1" name="needNickname" id="needn"><label for="needn">启用</label>&nbsp;&nbsp;
                            </div>
                            <div class="ui-form-item ">
                                <label class="ui-label">性别要求</label>
                                <input type="radio"  <{if $data['needSex'] neq 1}>checked<{/if}> value="0" name="needSex" id="noneeds"><label for="noneeds">不启用</label>&nbsp;&nbsp;
                                <input type="radio"  <{if $data['needSex'] eq 1}>checked<{/if}> value="1" name="needSex" id="needs"><label for="needs">启用</label>&nbsp;&nbsp;
                            </div>
                            <div class="ui-form-item ">
                                <label class="ui-label">年龄要求</label>
                                <input type="radio"  <{if $data['needAge'] neq 1}>checked<{/if}> value="0" name="needAge" id="noneed"><label for="noneed">不启用</label>&nbsp;&nbsp;
                                <input type="radio"  <{if $data['needAge'] eq 1}>checked<{/if}> value="1" name="needAge" id="need"><label for="need">启用</label>&nbsp;&nbsp;
                            </div>

                        </span>
                    </div>


                    <div class="ui-form-item ">
                        <label class="ui-label">是否配送</label>
                        <input type="radio"  <{if $data['needDeliver'] neq 1}>checked<{/if}> value="0" name="needDeliver" id="noneedd"><label for="noneedd">不启用</label>&nbsp;&nbsp;
                        <input type="radio"  <{if $data['needDeliver'] eq 1}>checked<{/if}> value="1" name="needDeliver" id="needd"><label for="needd">启用</label>&nbsp;&nbsp;
                    </div>
                    <div class="ui-form-item ">
                        <label class="ui-label">活动模式</label>
                        <input type="radio" id="filter" checked value="filter" name="model" required><label for="filter">官方筛选</label>&nbsp;&nbsp;
                        <input type="radio" id="first" <{if 'first' eq $data['model']}>checked<{/if}> value="first" name="model" required><label for="first">先到先得</label>&nbsp;&nbsp;
                        <{if $randomModel}><input type="radio" id="random" <{if 'random' eq $data['model']}>checked<{/if}> value="random" name="model" required><label for="random">随机</label><{/if}>
                    </div>
                    <div class="ui-form-item">
                        <label class="ui-label ">活动费用</label>
                        <input type="text" class="ui-text" id="showEventPay" value="<{$data['showPay']}>" name="showPay" placeholder="例如：免费/收费￥50" required/>
                        <i>仅用于前端列表显示</i>
                    </div>
                    <{if $originalPriceSwitch}>
                        <div class="ui-form-item ">
                            <label class="ui-label">原价</label>
                            <input type="number" class="ui-text" name="originalPrice" value="<{$data['originalPrice']}>" placeholder="89.00" required/>
                        </div>
                    <{/if}>

                    <{if $currentPriceSwitch}>
                        <div class="ui-form-item ">
                            <label class="ui-label">现价</label>
                            <input type="text" class="ui-text" name="price" value="<{$data['price']}>" placeholder="0.00" required/>
                        </div>
                    <{/if}>

                        <div class="ui-form-item " style="vertical-align:top;">
                                <label class="ui-label">积分</label>
                                <input class="ui-text " name="point" value="<{$data['point']}>" type="number" />
                        </div>
                        <div class="ui-form-item " style="vertical-align:top;">
                                    <label class="ui-label">名额</label>
                                    <input class="ui-text " name="places" type="number" value="<{$data['places']}>" style="width:115px;" required placeholder="0表示不限" />
                                    <input class="ui-text " name="placesUnit" type="text" value="<{$data['placesUnit']|default:'组'}>" style="width:50px;" required placeholder="名额单位：组，名" />
                        </div>
                    <{if $randomModel}>
                        <div class="ui-form-item random" style="vertical-align:top;">
                                    <label class="ui-label">中奖概率</label>
                                    <input class="ui-text " name="probability" value="<{$data['probability']}>" type="text" style="width:40px;" placeholder="0.1" />
                                    <i>0-1之间 小数点三位</i>
                        </div>
                        <div class="ui-form-item random" style="vertical-align:top;">
                                    <label class="ui-label">关联商品</label>
                                    <select name="relation" class="ui-select" style="width:115px;">
                                        <option value="point_mall" <{if 'point_mall' eq $data['relation']}>selected<{/if}>>积分商城</option>
                                    </select>
                                    <select name="relationId" class="ui-select" style="width:115px;">
                                        <option value="0" >请选择</option>
                                        <{foreach from=$pointMall item=item}>
                                        <option value="<{$item['id']}>" <{if $item['id'] eq $data['relationId']}>selected<{/if}> ><{$item['titleInner']}></option>
                                        <{/foreach}>
                                    </select>
                                   <!-- <input type="button" value="筛选器" class="ui-button fade-o-butn"/> -->
                        </div>
                        <div class="ui-form-item random" style="vertical-align:top;">
                                    <label class="ui-label">商品折扣</label>
                                    <input class="ui-text " name="discount" style="width:30px;" value="<{$data['discount']}>" type="text" />
                                    <i>0-1之间 小数点两位(向上取整)</i>
                        </div>
                    <{/if}>

                        <div class="ui-form-item" style="vertical-align:top;">
                            <label class="ui-label">跳转方式</label>
                            <input type="radio" id="jumpNo"  value="0" name="jumpMode"      required <{if 0 eq $data['jumpMode']}>checked<{/if}>><label for="jumpNo">无跳转</label>&nbsp;&nbsp;
                            <input type="radio" id="jumpList"  value="1" name="jumpMode"    required <{if 1 eq $data['jumpMode']}>checked<{/if}>><label for="jumpList">列表跳转</label>&nbsp;&nbsp;
                            <input type="radio" id="jumpDetail"  value="2" name="jumpMode"  required <{if 2 eq $data['jumpMode']}>checked<{/if}>><label for="jumpDetail">详情跳转</label>&nbsp;&nbsp;
                        </div>

                        <div class="ui-form-item" id="jumpURL" style="vertical-align:top;display: none;">
                            <label class="ui-label">跳转地址</label>
                            <input class="ui-text " name="jumpURL" value="<{$data['jumpURL']}>" type="text" />
                        </div>


                        <div class="ui-form-item">
                            <label class="ui-label">上线时间</label>
                            <input id="beginShowTime" name="beginShowTime" readonly class="ui-select" value='<{$data["beginShowTime"]|date_format:"%Y-%m-%d %H:%M"}>' type="text" />
                        </div>

                        <!--<div class="ui-form-item">-->
                            <!--<label class="ui-label">活动开始时间</label>-->
                            <!--<input id="startDate" name="startTime" value='<{$data["startTime"]|date_format:"%Y-%m-%d %H:%M:%S"}>' readonly class="date ui-select" type="text" required/>-->
                        <!--</div>-->

                        <!--<div class="ui-form-item ">-->
                            <!--<label class="ui-label ">活动结束时间</label>-->
                            <!--<input id="endDate" name="endTime" readonly value='<{$data["endTime"]|date_format:"%Y-%m-%d %H:%M:%S"}>' class="date ui-select" type="text" required/>-->
                        <!--</div>-->
                        <div class="ui-form-item ">
                            <label class="ui-label ">报名时间</label>
                            <input style="width: 13%" id="startDate2" name="applyStartTime" readonly value='<{$data["applyStartTime"]|date_format:"%Y-%m-%d %H:%M"}>' class="date ui-select" type="text" required/>-<input style="width: 13%"  id="endDate2" name="applyEndTime" readonly value='<{$data["applyEndTime"]|date_format:"%Y-%m-%d %H:%M"}>' class="date ui-select" type="text" required/>
                        </div>

                        <div class="reply_box">
                            <label class="ui-label">活动详情</label>
                            <textarea id="editor" name="content" class="edui-default inline-block" ><{$data['content']}></textarea>
                        </div>
                    <{if $clientShowSwitch}>
                        <div class="ui-form-item ">
                            <label class="ui-label">展现渠道</label>
                            <{html_checkboxes name="clientShow" options=$clientShow checked=$selectedClients  separator="&nbsp;"}>
                        </div>
                    <{/if}>
                    <{if $handInTask neq 0}>
                        <div class="ui-form-item ">
                            <label class="ui-label">交作业</label>
                            <input type="radio" value="1" id="handIn" name="task" required <{if $data['task'] eq 1}>checked<{/if}>/><label for="handIn">交作业</label>
                            <input type="radio" value="0" id="no-handIn" name="task" required <{if $data['task'] eq 0}>checked<{/if}>/><label for="no-handIn">不交作业</label>
                        </div>
                    <{/if}>
                    <div class="ui-form-item ">
                        <label class="ui-label">要求关注公众号</label>
                        <input type="radio" value="0" id="f0" style="display: none" name="mustFollow" required <{if $data['mustFollow'] eq 0}>checked<{/if}>/><label for="f0" style="display: none">无要求</label>
                        <{*<input type="radio" value="1" id="f1" name="mustFollow" required <{if $data['mustFollow'] eq 1}>checked<{/if}>/><label for="f1">必须关注</label>*}>
                        <input type="radio" value="1" id="f2" name="mustFollow" required checked /><label for="f2">必须关注</label>
                    </div>
                        <div class="reply_box">
                            <label class="ui-label">分享详情</label>
                            <div class="reply_con inline-block">
                                <input type="text" name="shareUri" value="<{$data['shareUri']}>" class="ui-text" />
                            </div>
                        </div>


                </div>
                <div class="integral_btn-group">
                    <input type="submit" value="提交" class="ui-button"/>
                    <input type="hidden" name="id" value="<{$id}>" class="ui-button"/>
                </div>

                </form>
            </div>
		</div>


        <{include file="Public/foot.html" }>

        <{include file="Public/ueditor.html" }>
		<script>
            var eventsAdd = "<{U('Events/add')}>";
            var eventsEdit = "<{U('Events/edit')}>";
            var eventsTypeManage = "<{U('Events/eventsTypeManage')}>";

            datePickter('beginShowTime');
            datePickter('startDate','endDate');
            datePickter('startDate2','endDate2');

            $(document).ready(function(){
                $(":radio").on("change",function(){
                    if ($('input:radio[name="model"]:checked').val() == 'random') {
                        $(".random").show();
                    } else {
                        $(".random").hide();
                    }
                });
                $(":radio").trigger('change');

                $("input[name='jumpMode']").on('change',function () {
                   if($('input[name="jumpMode"]:checked').val() == 0){
                       $("#jumpURL").hide();
                   } else{
                       $("#jumpURL").show();
                   }
                });

                $("#eventsTypeManage").on('click', function () {
                    $.getJSON(eventsTypeManage,{}, function(data){
                        if(data.status!=0){
                            layer.msg("数据获取失败，请稍后重试或联系管理员解决！");
                        }else{
                            var details = dialog({
                                title: '类型管理'
                                ,width: 700
                                ,content:  data.html
                            });
                            details.showModal();
                        }
                    });
                });






                $("form").submit(function () {
                    if( !$("#imgList").val() ){
                        layer.msg('请上传封面图片！');
                        return false;
                    }
                    if( !UE.getEditor('editor').getContent() ){
                        layer.msg('请填写活动详情！');
                        return false;
                    }
                    //return true;
                    $.post(eventsEdit,$(this).serialize(), function(data){
                        if(data.status!=0){
                            if(data.mark){
                                layer.msg(data.mark);
                            }else{
                                layer.msg(data.msg);
                            }

                        }else{
                            layer.msg(data.msg);
                            location.href = eventsAdd+'&id='+data.id;
                        }
                    }, 'json');
                    return false;
                });



            });

            (function ($) {
                'use strict';
                $.fn.uploader = function () {
                    return this.each(function () {
                        var $this = $(this);
                        var $img = $this.find('img');
                        var $file = $this.find('input[type=file]');
                        var $hidden = $this.find('input[type=hidden]');
                        var $txt = $this.find('i.uptxt');
                        // var $size = $this.find('span.size');
                        /*$img.on('load', function () {
                         var width = $(this).width();
                         var height = $(this).height();
                         $hidden.val($img.attr('src'));
                         $size.text(width + 'x' + height);
                         });*/
                        $file.AjaxFileUpload({
                            action: './api.php?m=Api&c=index&a=ajaxUpload&from=IMG_EVENT_LIST,IMG_ARTICLE_INFO_ABOUT,IMG_EVENT_APPLY',
                            onSubmit: function () {
                                $txt.text('上传中');
                            },
                            onComplete: function (filename, response) {
                                if(parseInt(response.id)>0){
                                    $txt.text("上传成功");
                                    $('#imgBox').show();
                                    $hidden.attr('value', response.msg);
                                    $img.attr("src",response.msg);
                                }else{
                                    $txt.text(response.msg);
                                }

                            }
                        });
                    });
                }
            })(jQuery);

            $('.uploader').uploader();

            //删除图片
            function deleteListPic() {
                $('#imgBox').hide();
                $('.uptxt').text('上传图片');
                $('#imgList').val('');
            }


            function addExt(){
                $('#other').append(
                    "<li>\n" +
                    "                                    <span >字段名称<a href=\"javascript:void(0)\" onclick=\"delExt(this)\">(删除)</a>：<input class=\"ui-text \" name=\"field_title[]\" value='' style=\"display: inline-block;width: 6rem\"/></span>\n" +
                    "                                    <span style=\"display: inline-block\">补充说明：<input class=\"ui-text \"  name=\"field_tip[]\"  value=''></input></span>\n" +
                    "                                </li>"

                );
            }


            function delExt(e){
                $(e).parentsUntil('ul').remove();
            }

		</script>
	</body>
</html>
